package com.example.allplan.RecyclerAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.allplan.JavaBean.YiGeChouQian;
import com.example.allplan.JavaBean.YiGeQianJavaBean;
import com.example.allplan.R;

import java.util.ArrayList;

public class QianLieBiaoAdapter extends RecyclerView.Adapter<QianLieBiaoAdapter.ViewHolder> {
    ArrayList<YiGeQianJavaBean> mList;
    QianLieBiaoAdapter.onItemClickListener mListener;
    Context mcon;
    public QianLieBiaoAdapter(ArrayList<YiGeQianJavaBean> m,QianLieBiaoAdapter.onItemClickListener mL, Context mcon){
        mListener=mL;
        mList=m;
        this.mcon=mcon;
    }


    public interface onItemClickListener{
        void onClick(int pos, Context mcon);
    }
    public QianLieBiaoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.yi_ge_chou_qian_item_view, parent, false);
        return new QianLieBiaoAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final QianLieBiaoAdapter.ViewHolder holder, final int position) {
        if(mList.get(position).getXian_shi()==0) holder.ming_cheng_textview.setText(mList.get(position).getChou_qian_ming());
        else if(mList.get(position).getXian_shi()==1)holder.ming_cheng_textview.setText("????");
        holder.item_linear_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClick(holder.getAdapterPosition(),mcon);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView ming_cheng_textview;
        LinearLayout item_linear_view;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ming_cheng_textview=itemView.findViewById(R.id.xian_shi_ming_cheng_textview);
            item_linear_view=itemView.findViewById(R.id.xian_shi_gen_view);
        }

    }
}
